<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>逾期催收列表 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">任务人</div>
                    <div class="field">
                        <input name="usrNm" id="usrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同编号</div>
                    <div class="field">
                        <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">事业部</div>
                    <div class="field">
                        <input name="buOrgCd" id="buOrgCd" placeholder="请选择" ltype="combobox">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">逾期天数</div>
                    <div class="field">
                        <input ligerui="width: 82" name="ovdDaysMin" id="ovdDaysMin" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                        -
                        <input ligerui="width: 82" name="ovdDaysMax" id="ovdDaysMax" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">应收日期</div>
                    <div class="field">
                        <input ligerui="width: 82" name="ovdDtMin" id="ovdDtMin" type="text" class="ui-datepicker"
                               value="">
                        -
                        <input ligerui="width: 82" name="ovdDtMax" id="ovdDtMax" type="text" class="ui-datepicker"
                               value="">
                    </div>
                </div>
                 <div class="fieldBox" id="searchPrjTypCdId">
              <div class="label">项目类型</div>
                <div class="field">
                <select name="prjTypCd"  id="prjTypCd" >
                 <option value="  " selected="selected">请选择</option>
                 <c:forEach items="${projectTypeList}" var="opt">
                  <option value="${opt.key}">${opt.value}</option>
                 </c:forEach>
                </select>
                </div>
            </div>
                 <div class="fieldBox col_33" id="searchInsCodeId">
                   <div class="label">第三方机构</div>
                             <div class="field">
                               <select name="insCode"  id="insCode" >
                                <option value="  " selected="selected">请选择</option>
                              <c:forEach items="${friBaseList}" var="fri">
                               <option value="${fri.insCode}">${fri.fundRasInsNm}</option>
                              </c:forEach>
                             </select>
                             </div>
                   </div>
                
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <%--<sys:funcAuth resCd="ovdExportBtn">
                        <span id="exportXlsxBtn" class="sq-button sq-button-round">导出</span>
                    </sys:funcAuth>--%>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
                <div class="clearFix"></div>
            </div>
        </form>
    </div>
    <div class="sqPanel" style="margin-bottom: 0;">
        <div class="sqPanel_head">
            <table class="table_full">
                <tr>
                    <td><b>应收总金额合计(元): </b><span id="arAmt"/></td>
                    <td><b>逾期金额合计(元): </b><span id="ovdAmt"/></td>
                    <td><b>罚息金额合计(元): </b><span id="fineAmt"/></td>
                </tr>
            </table>
        </div>
        <div class="sqPanel_body">
            <div id="ligergrid1" class="sq-grid"></div>
        </div>
    </div>
</div>


<div  style="display:none">
	<div id= "configDilog" >
	   <form id="mainGoodsCd_formSet">
		<div class="fieldset1 tabel_col clearFix">
			<div class="fieldBox col_100_auto">
				<div class="label">主货物大类</div>
				<div class="field">
					<select name="mainGoodsCd" id="mainGoodsCd" data-value=" " onchange="getGoods();">
						<option value=" " checked >请选择</option>
						<c:forEach items="${mainGdsTypCdList }" var="kv">
							<option value="${kv.key }">${kv.value }</option>
						</c:forEach>
					</select>
				</div>
			</div>
			
			<div class="fieldBox col_100_auto">
				<div class="label">主运输货物</div>
				<div class="field">
					<select name="goods" id="goods" data-value=" " onchange="checkGoods();">
					</select>
				</div>
			</div>
			
		</div>
	 </form>
	</div>
</div>

<script type="text/javascript">
    var grid = null, form = null,mainGoodsCdform =null;
    $(function () {
    	mainGoodsCdform = $("#mainGoodsCd_formSet").ligerForm();
    	
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/risk/ovdCollect/initOvdList.do?queryType=${queryType}',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', minWidth: 200, align: 'left', enabledSort: false, render: function (rowdata, rowindex, value, column) {
                        if(StringUtils.isEmpty(value)){
                            value = "";
                        }
                        var h = '';
                        h='<a href="javascript:showDetail(';
                        h+="'"+rowdata.cstId+"'";
                        h+=')">'+value+'</a>'
                        return h;
                    }},
                {display: '逾期合同数', name: 'ovdCntQty', width: 100, align: 'right', enabledSort: false},
                {display: '逾期支付表数', name: 'ovdPayQty', width: 100, align: 'right', enabledSort: false},
                {display: '逾期天数', name: 'ovdDays', width: 100, align: 'right', enabledSort: false},
                {
                    display: '应收金额(元)', name: '', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '<a style="cursor: pointer;" onclick="calcInterest(' + index + ');">&yen;' + FormatMoney(rowdata.arAmt/100) + '</a> ';
                    }
                },
                {
                    display: '逾期金额(元)', name: 'ovdAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.ovdAmt / 100);
                    }
                },
                {
                    display: '罚息金额(元)', name: 'fineAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fineAmt / 100);
                    }
                },

                {
                    display: '操作', width: 250, align: 'left', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="repaymentDtl(' + rowdata.cstId + ',\'' + rowdata.cstNm + '\');"><i class="sqBtnIco_49"></i>还款明细</a>  ' +
                                '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="overdueDtl(' + rowdata.cstId + ');"><i class="sqBtnIco_50"></i>逾期明细</a> ' +
                                '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="qyCommRec(' + rowdata.cstId + ',\'' + rowdata.cstNm + '\');"><i class="sqBtnIco_51"></i>催收记录</a>';
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: false,
            onBeforeShowData: function () {
                var grid = this;
                grid.collapsedRows = [];
            },
            detail: {
                height: 'auto',
                onShowDetail: showDetail_grid
            }
        });
        grid.setHeight(100);

        //事业部
        $("#buOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        form = $("#searchBar").ligerForm();
        liger.get("buOrgCd").setData(${buOrgCdList});

        getOvdAmtSummary();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
            //detailGrid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });
        
      //导出
        $("#exportXlsxBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                url: '<%=path%>/risk/ovdCollect/exportOverdueInfoList.do?queryType=${queryType}',
                data:data,
                beforeSend:function(){
                    wait_dialog=$.ligerDialog.SQalert({content: '正在导出...',SQ_type: "waitting"});
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        window.open(msg.data);
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        }); 
        
        //导出PDF
        $("#exportPdfBtn").click(function (event) {
            exportOverDue("pdf");
        });
        //导出Excel
        /*$("#exportXlsBtn").click(function (event) {
            exportOverDue("xls");
        });*/
    });
    // 客户详情页面
    function showDetail(_id){
        parent.parent.mainApp.f_addTab('tab_customer_np_detail'+_id,'客户详情','<%=path%>/customer/cstbscinfo/showDetail.do?id='+_id);
        <%--parent.pageInTab.addTabItem({tabid:'tab_customer_np_detail'+_id,text:'客户详情',url:'<%=path%>/customer/cstbscinfo/showDetail.do?id='+_id});--%>
    }

    //查询汇总
    function getOvdAmtSummary() {
        var data = form.getData();
        $.ajax({
            type: 'get',
            dataType: 'json',
            data: data,
            url: '<%=path%>/risk/ovdCollect/ovdAmtSummary.do?queryType=${queryType}',
            success: function (msg) {
                if (msg.success == 1) {
                    $("#arAmt").text(FormatMoney(msg.data.arAmt / 100));
                    $("#ovdAmt").text(FormatMoney(msg.data.ovdAmt / 100));
                    $("#fineAmt").text(FormatMoney(msg.data.fineAmt / 100));
                }
            }
        });
    }

    /* 还款明细 */
    function repaymentDtl(cstId, cstNm) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 850,
            height: 500,
            title: '还款明细',
            url: '<%=path%>/capital/capOverdueInfo/toRepaymentDtl.do?cstId=' + cstId + "&cstNm=" + cstNm,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }

    /* 逾期明细 */
    function overdueDtl(cstId) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 850,
            height: 500,
            title: '逾期明细',
            url: '<%=path%>/capital/capOverdueInfo/toOverdueDtl.do?cstId=' + cstId,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }


    //逾期明细列表
    function showDetail_grid(row, detailPanel, callback) {
    	
   	 //货物种类
		var prdTypCdSelect='select'
       var prdTypCdJSON = [];
       <c:if test="${not empty prdTypCdList}">
       prdTypCdJSON = ${prdTypCdList};
       </c:if>
   	
    	
    	
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);
        detailGrid = $(gridBox).ligerGrid({
            url: '<%=path%>/risk/ovdCollect/searchOvdDtlList.do?cstId=' + row.cstId +'&queryType=${queryType}',
            method: 'get',
            columns: [
                {
                    display: '支付表状态', name: 'prdStsCdNm', width: 80, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        if(rowdata.prdStsCdNm){
                            return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.prdStsCdNm + '">' + rowdata.prdStsCdNm + '</span>';
                        }else{
                            return '<span class="gridTip" style="cursor: pointer;" title="' + '正常' + '">正常</span>';
                        }
                    }
                },
                {display: '支付表', name: 'paySchNo', width: 160, align: 'left',
                    render: function (rowdata, index, value) {
                        if(null != rowdata.paySchNo && rowdata.paySchNo != ''){
                            return '<a href="javascript:showPaySchDetail('+rowdata.paySchId+')"'+'class="link">'+rowdata.paySchNo+'</a>';
                        }else{
                            return "";
                        }
                    }
                },
                { display: '项目类型', name: 'prdTypCdNm', width: 150, enabledSort:true},
                { display: '机构名称', name: 'fundRasInsNm', minWidth: 150 , enabledSort:true},
                {display: '紧急联系人', name: 'lkMan', width: 100, align: 'left'},
                {display: '联系电话', name: 'lkPhone', width: 100, align: 'left'},
                {display: '逾期日期', name: 'overdueDate', width: 90, align: 'center', render: renderDate},
                {display: '诉讼状态', name: 'sueStsCd', width: 90, align: 'center'},
                {
                    display: '逾期金额', name: 'overdueAmount', width: 90, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.overdueAmount / 100);
                    }
                },
                {
                    display: '罚息金额', name: 'penaltyAmount', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.penaltyAmount / 100);
                    }
                },
                {
                    display: '应收金额', name: 'recAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.recAmt / 100);
                    }
                },
                {display: '逾期天数<span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="当前逾期天数"></span>', name: 'overdueDay', width: 70, align: 'center'},
                {display: '最高逾期天数<span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="历史最高逾期天数"></span>', name: 'ovdMaxDay', width: 90, align: 'center'},
                /*{display: '应收时间', name: 'overdueDate', width: 100, align: 'center', render: renderDate},*/
                {display: '预约时间', name: 'appoDt', width: 100, align: 'center', render: renderDate},
                { display: '货物种类', minWidth: 200, isEllipsis: false,
                    render: function (rowdata, index, value) {
                    	if(rowdata.prdTypCdNm==null){
                    		 rowdata.prdTypCdNm='请选择货物类型<i class="ico_flasher"></i>';
                    	}
                        var h = '<div onclick="editNotes(event, detailGrid.rows['+index+'])">'+rowdata.prdTypCdNm+'</div>';
                        return h;
                    }
                }
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    }

    function editNotes(event, rowData) {
        var paySchId = rowData.paySchId;
            //$notesEdit = $('#configDilog');
        var onOk = function (item, Dialog) {
        	var goods = liger.get("goods");
        	var selectGoods = goods.getSelected();
        	if(!selectGoods){
      		  Dialog.hide();
      		  return;
      	     }
        	onModify(paySchId,selectGoods.id)
        	detailGrid.updateRow(rowData,{prdTypCdNm:selectGoods.text});
            Dialog.hide();
        };
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 600,
            height: 250,
            title : '货物种类',
            target : $('#configDilog'),
            buttons: [{
                    text: "确认", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
                },
                {
                    text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
                }
            ]
        });
    }


  //主货物大类change事件
    function getGoods(){
	 
    	var _PCode = $("#mainGoodsCd").val();
    	if(!_PCode) return;
    	$.ajax({
    		type: 'post',
    		dataType:'json',
    		data:{PCode:_PCode},
    		url: '<%=path%>/audit/audCreditInfo/getGoodsTypJSON.do',
    		success:function(msg){
    			if(msg.success == 1){
    				//主运输货物
    				var goods = $("#goods");
    				if(goods.length){
    					$("#goods").empty();
    					$("#goods").append("<option value=''>请选择</option>");
    					if(msg.data==null)return;
    					$.each(msg.data,function(index,obj) {
    						var option = "<option value='"+obj.key+"'>"+obj.value+"</option>";
    							$(option).appendTo("#goods");
    							liger.get("goods").setSelect();
    					});
    					
    				}
    				SetIframe_height();
    			}else{
    				top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
    			}
    		}
    	});
    }
  
    function checkGoods(){
    	var goods = liger.get("goods");
    	if(goods){
    		var selectGoods = goods.getSelected();
    	}
    }
    
    
    //修改类型
    function onModify(paySchId, value) {
        //如果客户恶意选中 这里将拦截
        if (StringUtils.isEmpty(value)) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_OPERATE_FAIL, SQ_type: "error"});
        }
        $.ajax({
            type: 'GET',
            dataType: 'json',
            url: '<%=path%>/risk/rentRemind/modifyPrdTypCd.do?paySchId=' + paySchId + '&value=' + value,
            success: function (msg) {
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    //grid.reload($('.pcontrol input', grid.toolbar).val());//加载到当前页
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
    
    //导出PDF、导出Excel
    function exportOverDue(format) {
        var form = liger.get("searchBar");
        var data = form.getData();
        var req = "format=" + format;
        for (name in data) {
            for (name in data) {
                if (data[name]) {
                    req = req + "&" + name + "=" + data[name];
                }
            }
        }
        window.location.href = "<%=path%>/capital/capOverdueInfo/exportOverdue.do?" + req;
    }

    //查询催收记录
    function qyCommRec(_cstId, _cstNm) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.open({
            width: 1110,
            height: 500,
            title: '催收记录',
            url: '<%=path%>/risk/rskCommRec/toListPage.do?cstId=' + _cstId + '&cstNm=' + _cstNm + '&qt=1',
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }

    //结算罚息
    function calcInterest(rowId) {
        var rowdata = grid.getRow(rowId);
        var req = "?cstId=" + rowdata.cstId + "&ovdDays=" + rowdata.ovdDays + "&fineAmt=" + rowdata.fineAmt + "&recAmt=" + rowdata.arAmt;
        $.ligerDialog.open({
            width: 450,
            height: 280,
            title: '应付金额计算',
            url: '<%=path%>/risk/ovdCollect/toCalcAmtPage.do' + req,

        });
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //查看支付表明细
    function showPaySchDetail(paySchId){
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '<%=path%>/risk/ovdCollect/getPayInfo.do?paySchId='+paySchId,
            success: function (msg) {
                    Add_navTab('tab_prj_quat_prps'+paySchId,'查看支付表','<%=path%>/project/prjprdpayschm/toDetailPage.do?id='+paySchId);
            }
        });
    }
</script>

</body>
</html>
